using System;
using System.ComponentModel.DataAnnotations;
using JGSY.CMS.LowCode.Platform.Domain.Enums;

namespace JGSY.CMS.LowCode.Platform.Application.DTOs
{
    /// <summary>
    /// 工作流实例数据传输对象
    /// 用于传输工作流实例的相关信息，包括执行状态、上下文数据等
    /// </summary>
    public class WorkflowInstanceDto
    {
        /// <summary>
        /// 工作流实例ID
        /// </summary>
        public long Id { get; set; }

        /// <summary>
        /// 工作流ID
        /// </summary>
        public long WorkflowId { get; set; }

        /// <summary>
        /// 实例名称
        /// </summary>
        [Required(ErrorMessage = "实例名称不能为空")]
        [StringLength(100, ErrorMessage = "实例名称长度不能超过100个字符")]
        public string InstanceName { get; set; } = string.Empty;

        /// <summary>
        /// 实例状态
        /// </summary>
        public WorkflowInstanceStatus Status { get; set; }

        /// <summary>
        /// 当前节点
        /// </summary>
        [StringLength(100, ErrorMessage = "当前节点长度不能超过100个字符")]
        public string? CurrentNode { get; set; }

        /// <summary>
        /// 发起人ID
        /// </summary>
        public long InitiatorId { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreatedAt { get; set; }

        /// <summary>
        /// 更新时间
        /// </summary>
        public DateTime UpdatedAt { get; set; }

        /// <summary>
        /// 完成时间
        /// </summary>
        public DateTime? CompletedAt { get; set; }

        /// <summary>
        /// 上下文数据（JSON格式）
        /// </summary>
        public string? ContextData { get; set; }

        /// <summary>
        /// 描述
        /// </summary>
        [StringLength(500, ErrorMessage = "描述长度不能超过500个字符")]
        public string? Description { get; set; }

        /// <summary>
        /// 优先级
        /// </summary>
        public int Priority { get; set; }

        /// <summary>
        /// 工作流名称
        /// </summary>
        public string? WorkflowName { get; set; }

        /// <summary>
        /// 发起人姓名
        /// </summary>
        public string? InitiatorName { get; set; }

        /// <summary>
        /// 状态文本
        /// </summary>
        public string? StatusText { get; set; }

        /// <summary>
        /// 执行时长（秒）
        /// </summary>
        public int? ExecutionDuration { get; set; }

        /// <summary>
        /// 是否运行中
        /// </summary>
        public bool IsRunning { get; set; }

        /// <summary>
        /// 是否已完成
        /// </summary>
        public bool IsCompleted { get; set; }

        /// <summary>
        /// 是否失败
        /// </summary>
        public bool IsFailed { get; set; }

        /// <summary>
        /// 进度百分比
        /// </summary>
        public decimal? Progress { get; set; }

        /// <summary>
        /// 当前任务数量
        /// </summary>
        public int CurrentTaskCount { get; set; }

        /// <summary>
        /// 已完成任务数量
        /// </summary>
        public int CompletedTaskCount { get; set; }

        /// <summary>
        /// 总任务数量
        /// </summary>
        public int TotalTaskCount { get; set; }
    }

    /// <summary>
    /// 启动工作流实例请求
    /// </summary>
    public class StartWorkflowInstanceRequest
    {
        /// <summary>
        /// 工作流ID
        /// </summary>
        [Required(ErrorMessage = "工作流ID不能为空")]
        public long WorkflowId { get; set; }

        /// <summary>
        /// 实例名称
        /// </summary>
        [Required(ErrorMessage = "实例名称不能为空")]
        [StringLength(100, ErrorMessage = "实例名称长度不能超过100个字符")]
        public string InstanceName { get; set; } = string.Empty;

        /// <summary>
        /// 描述
        /// </summary>
        [StringLength(500, ErrorMessage = "描述长度不能超过500个字符")]
        public string? Description { get; set; }

        /// <summary>
        /// 优先级
        /// </summary>
        [Range(0, 10, ErrorMessage = "优先级范围为0-10")]
        public int Priority { get; set; } = 0;

        /// <summary>
        /// 初始数据（JSON格式）
        /// </summary>
        public string? InitialData { get; set; }
    }

    /// <summary>
    /// 工作流实例查询请求
    /// </summary>
    public class WorkflowInstanceQueryRequest : PagedQueryDto
    {
        /// <summary>
        /// 工作流ID
        /// </summary>
        public long? WorkflowId { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public new WorkflowInstanceStatus? Status { get; set; }

        /// <summary>
        /// 发起人ID
        /// </summary>
        public long? InitiatorId { get; set; }

        /// <summary>
        /// 实例名称（模糊搜索）
        /// </summary>
        public string? InstanceName { get; set; }

        /// <summary>
        /// 创建时间开始
        /// </summary>
        public DateTime? CreatedAtStart { get; set; }

        /// <summary>
        /// 创建时间结束
        /// </summary>
        public DateTime? CreatedAtEnd { get; set; }

        /// <summary>
        /// 是否包含上下文数据
        /// </summary>
        public bool IncludeContextData { get; set; } = false;
    }

    /// <summary>
    /// 批量更新工作流实例状态请求
    /// </summary>
    public class BatchUpdateInstanceStatusRequest
    {
        /// <summary>
        /// 实例ID列表
        /// </summary>
        [Required(ErrorMessage = "实例ID列表不能为空")]
        public List<long> InstanceIds { get; set; } = new List<long>();

        /// <summary>
        /// 目标状态
        /// </summary>
        [Required(ErrorMessage = "目标状态不能为空")]
        public WorkflowInstanceStatus Status { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        [StringLength(500, ErrorMessage = "备注长度不能超过500个字符")]
        public string? Remark { get; set; }
    }
}
